package auction

import (
	"context"
	"hotgo/internal/model/input/form"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"

	"hotgo/api/api/auction/v1"
)

func (c *ControllerV1) AuctionList(ctx context.Context, req *v1.AuctionListReq) (res *v1.AuctionListRes, err error) {
	list, total, err := service.SysAuctionLog().ApiList(ctx, &req.AuctionApiLogListInp)
	if err != nil {
		return nil, err
	}
	res = new(v1.AuctionListRes)
	res.List = list
	res.PageRes.Pack(req, total)
	return
}

func (c *ControllerV1) AuctionDetail(ctx context.Context, req *v1.AuctionDetailReq) (res *v1.AuctionDetailRes, err error) {
	rdata, err := service.SysAuctionLog().ApiView(ctx, &req.AuctionLogViewInp)
	if err != nil {
		return nil, err
	}
	res = new(v1.AuctionDetailRes)
	res.AuctionLogViewModel = rdata
	return res, nil
}

func (c *ControllerV1) AuctionBidRankList(ctx context.Context, req *v1.AuctionBidRankListReq) (res *v1.AuctionBidRankListRes, err error) {
	list, total, err := service.SysAuctionBidHistory().ApiRank(ctx, &sysin.AuctionBidHistoryApiListInp{
		PageReq: form.PageReq{
			Page:       req.Page,
			PerPage:    req.PerPage,
			Pagination: req.Pagination,
		},
		LogID: req.LogID,
	})
	if err != nil {
		return nil, err
	}
	res = new(v1.AuctionBidRankListRes)
	res.List = list
	res.PageRes.Pack(req, total)
	return
}
func (c *ControllerV1) AuctionHome(ctx context.Context, req *v1.AuctionHomeReq) (res *v1.AuctionHomeRes, err error) {
	list, total, err := service.SysAuctionHome().ApiListAll(ctx)
	if err != nil {
		return nil, err
	}
	res = new(v1.AuctionHomeRes)
	res.List = list
	res.BidingTotal = total
	return
}
